package com.atguigu.day17.list03;

import org.junit.Before;
import org.junit.Test;

import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ListFor {
    List<String> list;
    @Before
    public void test00(){

        list = List.of("张三", "李四", "王五", "赵六", "陈一");
    }

    @Test
    public void test06(){
     //  list.forEach(System.out::println);
    }

    @Test
    public void test05(){
        ListIterator<String> listedIterator = list.listIterator(list.size());

        while (listedIterator.hasPrevious()) {
            String previous = listedIterator.previous();
            System.out.println("previous = " + previous);
        }
    }
    @Test
    public void test04(){
        ListIterator<String> listedIterator = list.listIterator();
        while (listedIterator.hasNext()){
            String next = listedIterator.next();
            System.out.println("next = " + next);
        }

        while (listedIterator.hasPrevious()){
            String previous = listedIterator.previous();
            System.out.println("previous = " + previous);
        }

    }

    @Test
    public void test03(){
       //todo 普通for
        for(int index = 0;index<list.size();index++){
            String ele = list.get(index);
            System.out.println("普通for = " + ele);
        }
    }


    @Test
    public void test01(){


        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String ele = iterator.next();
            System.out.println("Iterator = " + ele);
        }
    }
    @Test
    public void test02(){

        for (String s : list) {
            System.out.println("增强for = " + s);
        }
    }
}
